package com.sso.client.controller;

import com.sso.client.util.RespUtil;
import com.sso.core.login.SsoTokenLoginHelper;
import com.sso.core.login.SsoWebLoginHelper;
import com.sso.core.user.SsoUser;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class TestController {

    /**
     * 登出
     *
     * @return
     */
    @GetMapping(value = "/")
    public String index(HttpServletRequest request, HttpServletResponse response) {
        //如果对接的是vue或者app一般是用 SsoTokenLoginHelper.loginCheck
        SsoUser ssoUser = SsoWebLoginHelper.loginCheck(request, response);
        return "mysso单点登陆系统，登陆成功>" + ssoUser.getUsername();


    }

    /**
     * 登出
     *
     * @return
     */
    @PostMapping(value = "/logout")
    public String logout(HttpServletRequest request, HttpServletResponse response) {
        SsoTokenLoginHelper.logout(request);
        return RespUtil.respSucc();
    }


}
